#' @title GlowwormIntegrate
#' @description Integrate GlowwormScale objects
#' @param DataList a list of named GlowwormScale objects processed for the same target and secondary gene lists
#' @return This function takes a list of named GlowwormScale objects and produces a single GlowwormScale object containing:
#' \itemize{
#' \item MetaData - A copy of the metadata
#' \item GlowwormScaleOutput - A scaled data frame of n genes by n populations in metadata
#' \item RankScores - A data frame indicating the significantly enriched cell populations in the target gene list compared to the background lust
#' \item SumStats - A data frame showing expression level and specificity for each gene.
#' \item Settings - A list of settings
#' }
#'
#' @export
GlowwormIntegrate = function(DataList){
for(LL in 1:length(DataList)){
if(is.null(names(DataList[LL]))){
DATANAME = paste("Data", LL)
}else{
DATANAME = names(DataList[LL])
}
if(LL == 1){
DataRecompile = DataList[[LL]]
DataRecompile@MetaData$Dataset = DATANAME
DataRecompile@RankScores$Dataset = DATANAME
row.names(DataRecompile@GlowwormScaleOutput) = paste(row.names(DataRecompile@GlowwormScaleOutput), DATANAME, sep="^")
}else{
DataList[[LL]]@MetaData$Dataset = DATANAME
DataRecompile@MetaData = dplyr::bind_rows(DataRecompile@MetaData, DataList[[LL]]@MetaData)
row.names(DataList[[LL]]@GlowwormScaleOutput) = paste(row.names(DataList[[LL]]@GlowwormScaleOutput), DATANAME, sep="^")
DataRecompile@GlowwormScaleOutput = dplyr::bind_rows(DataRecompile@GlowwormScaleOutput, DataList[[LL]]@GlowwormScaleOutput)
DataList[[LL]]@RankScores$Dataset = DATANAME
DataRecompile@RankScores = dplyr::bind_rows(DataRecompile@RankScores, DataList[[LL]]@RankScores)
DataRecompile@SumStats = dplyr::bind_rows(DataRecompile@SumStats, DataList[[LL]]@SumStats)
DataRecompile@Settings[["InputFile"]] = paste(DataRecompile@Settings[["InputFile"]], DataList[[LL]]@Settings[["InputFile"]], sep = "/")
DataRecompile@Settings[["TargetGenes"]] = unique(c(DataRecompile@Settings[["TargetGenes"]], DataList[[LL]]@Settings[["TargetGenes"]]))
#DataRecompile@Settings[["SecondaryGenes"]] = DataRecompile@Settings[["SecondaryGenes"]]
DataRecompile@Settings[["UniqueSecondaryGenes"]] = intersect(DataRecompile@Settings[["UniqueSecondaryGenes"]], DataList[[LL]]@Settings[["UniqueSecondaryGenes"]])
DataRecompile@Settings[["N_Classes"]] = DataRecompile@Settings[["N_Classes"]] + DataList[[LL]]@Settings[["N_Classes"]]
DataRecompile@Settings[["N_Subclasses"]] = DataRecompile@Settings[["N_Subclasses"]] + DataList[[LL]]@Settings[["N_Subclasses"]]
DataRecompile@Settings[["N_TotalClusters"]] = DataRecompile@Settings[["N_TotalClusters"]] + DataList[[LL]]@Settings[["N_TotalClusters"]]
}
}
DataRecompile@Settings[["MissingTargetGenes"]] = NULL
DataRecompile@GlowwormScaleOutput = DataRecompile@GlowwormScaleOutput %>% dplyr::select(c( DataRecompile@Settings[["TargetGenes"]], DataRecompile@Settings[["UniqueSecondaryGenes"]]))
DataRecompile@SumStats = subset(DataRecompile@SumStats, row.names(DataRecompile@SumStats) %in% c(DataRecompile@Settings[["TargetGenes"]], DataRecompile@Settings[["UniqueSecondaryGenes"]]))
setMethod("show",signature = signature(object = "GlowwormObj"),
function(object){
print_message <- paste(c("\nGlowwormObj for ", DataRecompile@Settings$InputFile, " for ", length(unique(DataRecompile@Settings$TargetGenes)), "target genes and ", length(unique(DataRecompile@Settings$UniqueSecondaryGenes)), " background genes for ", DataRecompile@Settings$N_TotalClusters, " total clusters.\n", sep=""))
cat(print_message,sep = "")
})
return(DataRecompile)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.